<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>制定出库单</title>

    <link rel="stylesheet" href="../css/productionPlanRegistrationCss.css">

    <link rel="stylesheet" href="../static/css/style.css">

    <script src="../js/jquery-2.1.1.min.js"></script>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-table.min.css">
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>

    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="../static/js/global.min.js"></script>
    <script src="../js/bootstrap-table.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-table/1.21.0/locale/bootstrap-table-zh-CN.js"></script>
    <script>
        //渲染表格
        $(function () {
            let date = new Date();
            $('#checkTime').val(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());//审核时间
            //用户信息
            $.ajax({
                type:'POST',
                url: '/userShow.action',
                success:function (user){
                    $('#checker').val(user.loginId);
                }
            });
            $('#table').bootstrapTable({
                //请求方式  get请求中文会乱码，建议使用post请求
                method: 'post',
                //请求头部的设置
                contentType: 'application/json',
                //路径
                url: '/hj/queryWarehouseCheckTagApprove.action',
                //设置交替行样式
                striped: true,
                //初始显示页号
                pageNumber: 1,
                //设置表格高度
                height: 600,
                //是否显示分页
                pagination: true,
                //设置是服务端分页还是客户端分页
                sidePagination: 'server',
                //页大小
                pageSize:4,
                //分页列表
                pageList:[4,8],
                //上传到服务端的参数
                queryParams: function (params) {
                    return {
                        // 计算页号(当前页)
                        pageNum: (params.offset / params.limit) + 1,
                        // 计算页大小
                        pageSize: params.limit,

                    };
                },
                // 定义列名
                columns: [
                    {title: '申请单编号', field: 'payId', align: 'center'},
                    {title: '出库理由', field: 'reason', align: 'center'},
                    {title: '出库详细理由', field: 'reasonexact', align: 'center'},
                    {title: '登记人', field: 'register', align: 'center'},
                    {title: '登记时间', field: 'registerTime', align: 'center'},
                    {title: '总件数', field: 'amountSum', align: 'center'},
                    {title: '总金额（元）', field: 'costPriceSum', align: 'center'},
                    {title: '出库调度', field: 'checkTag', align: 'center',
                        formatter: function (value,row,index) {
                            return "<button data-toggle=\"modal\" data-target=\"#myModal\" class='btn btn-info' onclick='make("+JSON.stringify(row)+")'>出库调度</button>";
                        },
                    }
                ]
            });
        })
        var o="";

        function method(obj){
            $.ajax({
                type:'POST',
                url: '/hj/queryWarehouseDetailById.action',
                data:'id='+obj.id,
                success:function (resultSPayDetails){
                    $('#tbodyModal').html("");
                    $('#payId').val(obj.payId);
                    $('#reason').val(obj.reason);
                    $('#amount_sum').val(obj.amountSum);
                    $('#paid_amount_sum').val(obj.paidAmountSum);

                    $.each(resultSPayDetails,function (index,SPayDetail){
                        $('#tbodyModal').append("<tr>" +
                            "<td>"+SPayDetail.id+"</td>" +
                            "<td>"+SPayDetail.productId+"</td>" +
                            "<td>"+SPayDetail.productName+"</td>" +
                            "<td>"+SPayDetail.amount+"</td>" +
                            "<td>"+SPayDetail.paidAmount+"</td>" +
                            "<td><button data-toggle=\"modal\"  class='btn btn-info' onclick='dispatch("+SPayDetail.id+","+JSON.stringify(obj)+",this)'>"+(SPayDetail.payTag=='K002-1'?'出库调度':'已调度')+"</button></td>" +
                            "</tr>")
                    })
                }
            });
        }
        //审核
        function make(obj){
            o=obj;
            method(obj);
        }

        //调度产品编号
        var number=0;

        //调度
        function dispatch(id,obj,s){
            if($(s).text()!="已调度"){
                $.ajax({
                    type:'POST',
                    url:'/hj/queryWarehouseDispatchDetail.action',
                    data: 'id='+id,
                    success:function (resultSPayDetail){
                        $('#payId1').val(obj.payId);//出库单编号
                        $('#productId1').val(resultSPayDetail.product_id);//产品编号
                        $('#productName1').val(resultSPayDetail.product_name);//产品名称
                        $('#costPrice1').val(resultSPayDetail.cost_price);//成本单价
                        $('#s_amount').text(resultSPayDetail.number);//当前库存数量
                        $('.amount').val(resultSPayDetail.amount);//出库数量
                        $('#paidAmount').val(resultSPayDetail.paid_amount);//已出库件数
                        $('#register').val(obj.register);//登记人
                        $('#registerTime').val(obj.registerTime);//登记人
                        //设置要提交调度产品编号
                        number=resultSPayDetail.id;
                        $('#myModal1').modal("show");
                    }
                })
            }
        }
        var attemper="";
        //提交调度产品
        $(function (){
            $.ajax({
                type: 'POST',
                url: '/userShow.action',
                contentType: 'application/json;charset=utf-8',
                success: function (result) {
                    attemper=result.loginId;//设置调度人
                }
            })
            $('#submit').click(function (){
                let date = new Date();
                let dateTime = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();//登记时间
                let sPayViewObj={
                    sPay:{
                        id:o.id,//出库编号
                        attemper:attemper,//调度人
                        attemperTime:dateTime,//调度时间
                        storeTag:'K002-3',//库存调度标志 已调度
                    },
                    sPayDetails:{
                        id:number,//调度产品编号
                        payTag:'K002-3',//调度标志 已调度
                    }
                }

                $.ajax({
                    type:'POST',
                    contentType: 'application/json;charset=utf-8',
                    url:'/hj/updateWarehouseDispatchDetail.action',
                    data:JSON.stringify(sPayViewObj),
                    success:function (resultData){
                        if(resultData>0){
                            method(o);
                            $('#myModal1').modal("hide");
                            alert("成功操作一条数据");
                            $('#table').bootstrapTable("refresh");
                        }else {
                            alert("操作一条数据失败");
                        }
                    }
                })
            });
        })

    </script>
</head>
<body>

    <table id="table"></table>

    <div class="modal fade" id="myModal">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">

                <!-- 模态框头部 -->
                <div class="modal-header">
                    <h4 class="card-title">reviewProductionPlan</h4>
                    <div>
                        <button type="button" class="btn btn-dark" data-dismiss="modal" id="refuse">返回</button>
                    </div>
                </div>

                <!-- 模态框主体 -->
                <div class="modal-body">
                    <div class="d1">
                        <div style="margin-top: 10px"><h2>出库调度单</h2>

                        </div>
                        <div class="container-fluid row" style="margin-top: 10px">
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">申请单编号<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="payId" style="background-color: white" readonly>
                            </div>

                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">出库理由<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="reason" style="background-color: white" readonly>
                            </div>
                        </div>

                        <div class="container-fluid row">
                            <table class="table table-bordered" style="text-align: center">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>产品编号</th>
                                    <th>产品名称</th>
                                    <th>应出库件数</th>
                                    <th>已出库件数</th>
                                    <th>调度</th>
                                </tr>
                                </thead>
                                <tbody id="tbodyModal">


                                </tbody>
                            </table>
                        </div>

                        <div class="container-fluid row">
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">应出库总件数<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="amount_sum" style="background-color: white" readonly>
                            </div>
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">已出库总件数<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="paid_amount_sum" style="background-color: white" readonly>
                            </div>
                        </div>

                    </div>

                </div>

                <!-- 模态框底部 -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                </div>

            </div>
        </div>
    </div>

    <div class="modal fade" id="myModal1">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">

                <!-- 模态框头部 -->
                <div class="modal-header">
                    <h4 class="card-title">reviewProductionPlan</h4>
                    <div>
                        <button type="button" class="btn btn-info" data-dismiss="modal" id="submit">提交</button>
                        <button type="button" class="btn btn-dark" data-dismiss="modal">返回</button>
                    </div>
                </div>

                <!-- 模态框主体 -->
                <div class="modal-body">
                    <div class="d1">
                        <div style="margin-top: 10px"><h2>出库调度单</h2>

                        </div>
                        <div class="container-fluid row" style="margin-top: 10px">
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">出库单编号<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="payId1"  style="background-color: white" readonly>
                            </div>

                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">产品编号<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="productId1"  style="background-color: white" readonly>
                            </div>
                        </div>

                        <div class="container-fluid row">
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">产品名称<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="productName1"  style="background-color: white" readonly>
                            </div>

                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">成本单价<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="costPrice1" style="background-color: white" readonly>
                            </div>
                        </div>

                        <div class="container-fluid row">
                            <table class="table table-bordered" style="text-align: center">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>库房名称</th>
                                    <th>存储地址编号</th>
                                    <th>存储地址名称</th>
                                    <th>存储单元简称</th>
                                    <th>当前库存数量</th>
                                    <th>本次出库数量</th>
                                </tr>
                                </thead>
                                <tbody >
                                <tr>
                                    <td>1</td>
                                    <td>成品库</td>
                                    <td>01-01-01</td>
                                    <td>电子-计算机-服务器</td>
                                    <td></td>
                                    <td id="s_amount"></td>
                                    <td><input type="text" class="form-control amount" style="background-color: white" readonly>

                                </tbody>
                            </table>
                        </div>

                        <div class="container-fluid row">
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">应出库总件数<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control amount" style="background-color: white" readonly>
                            </div>
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">已出库总件数<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="paidAmount" style="background-color: white" readonly>
                            </div>
                        </div>

                        <div class="container-fluid row">
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">登记人<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="register" style="background-color: white" readonly>
                            </div>
                            <div class="input-group mb-4 col">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">登记时间<span class="text-danger scale5 ms-2">*</span></span>
                                </div>
                                <input type="text" class="form-control" id="registerTime" style="background-color: white" readonly>
                            </div>
                        </div>

                    </div>

                </div>

                <!-- 模态框底部 -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                </div>

            </div>
        </div>
    </div>


    <script src="../js/jquery.dataTables.min.js"></script>
</body>
</html>